#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc,char *argv[])
{
    if (argc < 2) {
        fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
        return 1;
    }
    for(int i=1;i<argc;i++){
        int fd=open(argv[i], O_RDONLY);
        if (fd < 0) {
            perror("Error opening file");
            continue;
        }
        char buffer[1024];
        ssize_t bytesRead;
        while ((bytesRead = read(fd, buffer, sizeof(buffer))) > 0) {
            if (write(STDOUT_FILENO, buffer, bytesRead) < 0) {
                perror("Error writing to stdout");
                close(fd);
                return 1;
            }
        }
        close(fd);
    }
    return 0;
}
